<?php

namespace Remoteshell\PhpBotSdk\loader;

use Exception;

class ComponentsRegister
{

    /** @var array  组件路由导航注册，这些对应路由将会被自动注册 */
    public static array $Components_Route = [];

    /**
     * 注册方法
     * @param $route_name
     * @param $components
     * @return void
     */
    public static function Register($route_name, $components): void
    {
       self::$Components_Route[$route_name] = $components;

    }

    /**
     * 调用注册的回调函数
     * @param $route_name
     * @param array $params
     * @return mixed
     * @throws Exception
     */
    public static function Call($route_name, array $params = [])
    {
        if (isset(self::$Components_Route[$route_name])) {
            return call_user_func_array(self::$Components_Route[$route_name], $params);
        } else {
            throw new Exception("Route not found: $route_name");
        }
    }
}